package test0928.deepclone;

public class Driver extends Person implements Cloneable{
    private Car car;

    public Driver() {
    }

    public Driver(int age, String name, Car car) {
        super(age, name);
        this.car = car;
    }

    public Driver(Car car) {
        this.car = car;
    }

//clone 深拷贝


    @Override
    public Object clone() throws CloneNotSupportedException {
        Driver driver = (Driver) super.clone();//super指向Person
        driver.car = (Car) driver.car.clone();//指向Car
        return driver;
    }

    public Car getCar() {
        return car;
    }

    public void setCar(Car car) {
        this.car = car;
    }

    @Override
    public String toString() {
        return "Driver{" +super.toString()+
                "car=" + car +
                '}';
    }
}
